<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./../template/WorkspaceTemplate.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:c="http://java.sun.com/jsp/jstl/core">

    <ui:define name="top">

    </ui:define>

    <ui:define name="left">

    </ui:define>

    <ui:define name="right">

    </ui:define>

    <ui:define name="content">
        <style>
            .inputBox {
                width: 50px;
            }
        </style>
        <h:form id="rfqSimu">
            <br/>
            <p:panel header="Information">
                <p:messages showDetail="true"/>
                <h:panelGrid columns="3" style="font-weight: bold" >
                    <h:outputLabel value="Product"/>
                    <h:outputLabel value="Requested Amount"/>
                    <h:outputLabel value="Current Inventory"/>

                    <c:forEach items="#{aTPManagerBean.pendingSO.deliveryOrder.itemLines}" var="item">
                        <h:outputText value="#{item.product.productType}"/>
                        <h:outputText value="#{item.qtyOrderedCase}"/>
                        <h:outputText value="#{aTPManagerBean.returnCurrentInventory(item.product.productType)}"/>
                    </c:forEach>

                </h:panelGrid>
                <p:panel header="Indicative Leadtime Info">
                    <h:outputLabel value="Indicative Leadtime"/>
                    <h:outputText value="#{aTPManagerBean.returnIndicativeLeadTime()}"/>
                </p:panel>
                <p:commandButton value="Simulate" ajax="true" update="rfqSimu" actionListener="#{aTPManagerBean.simulateSO}"/>
                <p:commandButton value="Reset" ajax="true" update="rfqSimu" actionListener="#{aTPManagerBean.resetFormData}"/>
                <p:commandButton value="Confirm" ajax="false" action="#{aTPManagerBean.confirmSOATPChecking}"/>
            </p:panel>
            <br/>
            <div style="border:1px solid gray;width:720px;overflow-y:hidden;overflow-x:scroll;">
                <p:dataTable var="day" value="#{aTPManagerBean.numOfDays}">
                    <f:facet name="header">  
                        Simulation for Sales Order
                    </f:facet> 

                    <p:columnGroup type="header">  
                        <p:row>  
                            <p:column rowspan="4" headerText="Date" />  
                            <p:column colspan="16" headerText="Demand" />  
                        </p:row>  

                        <p:row>  
                            <p:column colspan="8" headerText="Daily Demand" />  
                            <p:column colspan="8" headerText="Daily Overtime Demand" />  
                        </p:row>  

                        <p:row>  
                            <p:column colspan="2" headerText="A" />  
                            <p:column colspan="2" headerText="B" />  
                            <p:column colspan="2" headerText="C" />  
                            <p:column colspan="2" headerText="D" />
                            <p:column colspan="2" headerText="A" />  
                            <p:column colspan="2" headerText="B" />  
                            <p:column colspan="2" headerText="C" />  
                            <p:column colspan="2" headerText="D" />  
                        </p:row>  

                        <p:row>
                            <c:forEach items="#{aTPManagerBean.counterForProduct}" var="counter">
                                <p:column headerText="Orig."/>
                                <p:column headerText="New"/>
                            </c:forEach>
                            <c:forEach items="#{aTPManagerBean.counterForProduct}" var="counter">
                                <p:column headerText="Orig."/>
                                <p:column headerText="New"/>
                            </c:forEach>
                        </p:row>

                    </p:columnGroup>

                    <p:column>
                        <h:outputText value="#{aTPManagerBean.returnCalendarString(aTPManagerBean.changedDates.get(day))}"/>
                    </p:column>

                    <c:forEach items="#{aTPManagerBean.counterForProduct}" var="cfp">
                        <p:column>
                            <h:outputText value="#{aTPManagerBean.origDailyDemands.get(cfp).get(day)}"/>
                        </p:column>

                        <p:column>
                            <p:inputText styleClass="inputBox" value="#{aTPManagerBean.dailyDemands.get(cfp).get(day).l}"
                                         required="true" requiredMessage="Please fill in all the fields"/>
                        </p:column>
                    </c:forEach>

                    <c:forEach items="#{aTPManagerBean.counterForProduct}" var="cfp">
                        <p:column>
                            <h:outputText value="#{aTPManagerBean.origOtDailyDemands.get(cfp).get(day)}"/>
                        </p:column>

                        <p:column>
                            <p:inputText styleClass="inputBox" value="#{aTPManagerBean.otDailyDemands.get(cfp).get(day).l}"
                                         required="true" requiredMessage="Please fill in all the fields"/>
                        </p:column>
                    </c:forEach>
                </p:dataTable>
            </div>

        </h:form>
        <br/>
        <br/>
        <h:form id="legend">
            <p:panel>
                <h:panelGrid columns ="8">
                    <c:forEach items="#{aTPManagerBean.counterForProduct}" var="item">
                        <h:outputText value="#{aTPManagerBean.returnProductAlpha(item)}" />
                        <h:outputText value="#{aTPManagerBean.returnProductName(item)}"/>
                        <h:outputLabel value=""/>
                        <h:outputLabel value=""/>
                    </c:forEach>
                </h:panelGrid>
            </p:panel>
        </h:form>
    </ui:define>

    <ui:define name="bottom">

    </ui:define>

</ui:composition>
